/**
 * @date 2015年12月15日 下午3:17:09
 * @version V1.0
 */
package MLDA_Process;

import java.util.ArrayList;
import java.util.HashMap;

import Commons.LDAFileProcess;
import Commons.utils;

/**
 * @ClassName: Reformatter
 * @Description: 将LDA结果转换成新的文档
 * @author ffftzh
 * @date 2015年12月15日 下午3:17:09
 *
 */
public class Reformatter {

    public static String ReformatLDAResults(String wordmapPath, String tassignPath) throws Exception {
        String new_corpus_path = utils.get_parent_path(tassignPath) + "/new_corpus.txt";
        LDAFileProcess LDA_result = new LDAFileProcess();
        LDA_result.read_wordMap(wordmapPath);
        LDA_result.read_Tassign(tassignPath);

        HashMap<String, ArrayList<String>> new_corpus = new HashMap<String, ArrayList<String>>();
        for (ArrayList<String[]> oneTassign : LDA_result.getTassign()) {
            for (String[] tassignItem : oneTassign) {
                if (!new_corpus.containsKey(tassignItem[1])) {
                    new_corpus.put(tassignItem[1], new ArrayList<String>());
                }
                new_corpus.get(tassignItem[1]).add(LDA_result.getIndex2Word().get(Integer.parseInt(tassignItem[0])));
            }
        }
        LDA_result.setCorpus((ArrayList<ArrayList<String>>) utils.hash2Array(new_corpus));
        LDA_result.write_corpus(new_corpus_path, true);

        return new_corpus_path;

    }
}
